/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.aaron.platform.entity;

import java.io.Serializable;
import javax.persistence.*;
import java.util.List;

/**
 * 车辆基本信息
 * @author aaronbamboo
 */
@Entity
@Table(name = "wlb_motor_info")
@SequenceGenerator(name="WLB_MOTOR_INFO_GENERATOR", sequenceName="WLB_MOTOR_INFO_GENERATOR", allocationSize = 1)
public class WlbMotorInfo extends BaseObject implements Serializable {
    
    private static final long serialVersionUID = 1L;
    
    public final static String PROPERTY_DOMAIN_ID = "domainInfo.domainId";
    
    public final static String PROPERTY_MOTOR_NUMBER = "motorNum";
    
    public final static String PROPERTY_DRIVER_NAME = "driverName";
    
    public final static String PROPERTY_IS_BOOKED = "isBooked";
    
    public final static int INT_NOT_BOOKED = 1;
    
    public final static int INT_IS_BOOKED = 2;
    
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO, generator="WLB_MOTOR_INFO_GENERATOR")
    @Column(name = "motor_id")
    private Integer motorId;
    
    /** 车牌号 */
    @Column(name = "motor_num")
    private String motorNum;
    
    /** 型号 */
    @Column(name = "motor_style")
    private String motorStyle;
    
    /** 驾驶员名 */
    @Column(name = "driver_name")
    private String driverName;
    
    /** 型号 */
    @Column(name = "driver_phone")
    private String driverPhone;
    
    /** 对应的域信息 */
    @JoinColumn(name = "domain_id", referencedColumnName = "domain_id")
    @ManyToOne(optional = false, fetch = FetchType.EAGER)
    private ItscDomainInfo domainInfo;
    
    /** 
     * 不定义实体关系，通过手工查询获取
     */
    @Transient
    private List<WlbMotorBook> wlbMotorBooks;

    public ItscDomainInfo getDomainInfo() {
        return domainInfo;
    }

    public void setDomainInfo(ItscDomainInfo domainInfo) {
        this.domainInfo = domainInfo;
    }

    public String getDriverName() {
        return driverName;
    }

    public void setDriverName(String driverName) {
        this.driverName = driverName;
    }

    public String getDriverPhone() {
        return driverPhone;
    }

    public void setDriverPhone(String driverPhone) {
        this.driverPhone = driverPhone;
    }

    public Integer getMotorId() {
        return motorId;
    }

    public void setMotorId(Integer motorId) {
        this.motorId = motorId;
    }

    public String getMotorNum() {
        return motorNum;
    }

    public void setMotorNum(String motorNum) {
        this.motorNum = motorNum;
    }

    public String getMotorStyle() {
        return motorStyle;
    }

    public void setMotorStyle(String motorStyle) {
        this.motorStyle = motorStyle;
    }

    public List<WlbMotorBook> getWlbMotorBooks() {
        return wlbMotorBooks;
    }

    public void setWlbMotorBooks(List<WlbMotorBook> wlbMotorBooks) {
        this.wlbMotorBooks = wlbMotorBooks;
    }
    
    public boolean isBooked() {
        if (this.wlbMotorBooks == null) {
            return false;
        } else {
            return this.wlbMotorBooks.size()>0 ? true:false;
        } 
    }
    
    public boolean isMorningBooked() {
        if (this.wlbMotorBooks == null) {
            return false;
        } else {
            for (WlbMotorBook motorBook : wlbMotorBooks) {
                if (motorBook.getBookStyle() == WlbMotorBook.BOOK_STYLE_MORNING) {
                    return true;
                }
            }
            return false;
        }
    }
    
    public boolean isAfternoonBooked() {
        if (this.wlbMotorBooks == null) {
            return false;
        } else {
            for (WlbMotorBook motorBook : wlbMotorBooks) {
                if (motorBook.getBookStyle() == WlbMotorBook.BOOK_STYLE_AFTERNOON) {
                    return true;
                }
            }
            return false;
        }
    }
}
